/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plash.utils;

import plash.geom.Point;

/**
 *
 * @author User
 */
public class Math
{

    public static int distance(int x0, int y0, int x1, int y1)
    {
        int dx = x1 - x0;
        int dy = y1 - y0;
        int dx2 = dx * dx;
        int dy2 = dy * dy;

        return (int) java.lang.Math.sqrt(dx2 + dy2);
    }

    public static int distance(Point point1, Point point2)
    {
        return Math.distance(point1.getX(), point1.getY(), point2.getX(), point2.getY());
    }

    public static int interpolate(float x, float x1, float x2, float y1, float y2)
    {
        return (int) (((y2 - y1) / (x2 - x1)) * (x - x1));
    }

    public static int interpolate(int x, int x1, int x2, int y1, int y2)
    {
        return (int) (((y2 - y1) / (x2 - x1)) * (x - x1));
    }

    public static float toRadians(int degrees)
    {
        return (float) ((degrees / 180.0f) * 3.14);
    }

    public static int toDegrees(float radians)
    {
        return (int) ((radians / 3.14f) * 180);
    }
    
    public static float angle(Point center, Point straying)
    {
        return (float) java.lang.Math.atan2(straying.getY() - center.getY(), straying.getX() - center.getX());
    }

    public static Point getRotatedLocation(Point center, int radius, float angle)
    {
        Point location = new Point();
        location.setX((int) (java.lang.Math.cos(angle) * radius));
        location.setY((int) (java.lang.Math.sin(angle) * radius));
        location.offset(center);
        return location;
    }
}
